﻿#include <QCoreApplication>
#include <QThread>
#include <QLineF>
#include <random>

#include "QsLog/QsLog.h"
#include "common/common.h"
#include "breakpad/client/linux/handler/exception_handler.h"

#include "basemap.h"
#include "baserole.h"
#include "mapmanager.h"
#include "monsterrole.h"

static bool DumpCallback(const google_breakpad::MinidumpDescriptor &descriptor,
    void *context, bool success) {

  return true;
}

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    google_breakpad::MinidumpDescriptor minidump(".");
    google_breakpad::ExceptionHandler breakpad(minidump, NULL, DumpCallback, NULL,
        true, -1);

    init_log_file("gh_server_log.txt");

    srand(time(NULL));

    new MapManager();

    MapManager::getSingleton().loadSystemConfigFromINI(QCoreApplication::applicationDirPath()+"/resources/gh_sever_config.ini");
    MapManager::getSingleton().loadGradeFromXML(QCoreApplication::applicationDirPath()+"/resources/gradeinfo.xml");
    MapManager::getSingleton().loadMonsterFromXML(QCoreApplication::applicationDirPath()+"/resources/monsterinfo.xml");
    MapManager::getSingleton().loadBulletFromXML(QCoreApplication::applicationDirPath()+"/resources/bulletinfo.xml");
    MapManager::getSingleton().loadMapFromXML(QCoreApplication::applicationDirPath()+"/resources/mapinfo.xml");

    MapManager::getSingleton().startServer();

    int state = a.exec();

    delete MapManager::getSingletonPtr();

    return state;
}
